﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using FDEECommonTools;
using FDEEInterface;
using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FDEEDrawingModels
{
    public class PlotLineInfomationTable
    {
        #region 盖梁平面线路信息表
        /// <summary>
        /// 平面信息表绘制
        /// </summary>
        /// <param name="db"></param>
        /// <param name="scale"></param>
        /// <param name="dwgPath"></param>
        public static void DrawBeamLineInfomationTable(Database db, double scale, string dwgPath, string filepath, string pierPara,ref string pierdiv, string title = "MAINLINE",string tkPath="")
        {
            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Extents2d ext1 = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin.Convert2D(0, -2 * scale);
            Point2d M1 = CT;
            ext = new Extents2d(M1, M1);
            System.Data.DataTable dtA = new System.Data.DataTable();
            System.Data.DataTable dtB = new System.Data.DataTable();
  
            System.Data.DataTable dt;//= CVSTools.OpenCSV(@"C:\Users\huajie\Desktop\FDEE_Data\Banani EX-1 垫石坐标.csv");
            System.IO.FileInfo fileInfo = new System.IO.FileInfo(filepath);
            if (fileInfo.Extension.Contains("xlsx"))
                dt = new FDEECommonTools.ExcelHelper().ExcelToTableForXLSX(filepath);
            else
                dt = FDEECommonTools.CVSTools.OpenCSV(filepath);
            DataView dv0 = dt.DefaultView;
            dt = dv0.ToTable(true, new string[] { "Pier", "Side", "PlinthNo", "East", "North" });

            System.Data.DataTable dtP = new System.Data.DataTable();
            DataView dv = dt.DefaultView;
            dtP = dv.ToTable(true, new string[] { "Pier" });
            string[] pierL = pierPara.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(',');
            DataRow[] rows;
            if (pierL.Length >= 1 && !string.IsNullOrWhiteSpace(pierL[0]))
            {
                string s = "";
                for (int i = 0; i < pierL.Length; i++)
                {
                    if (string.IsNullOrWhiteSpace(s))
                        s = "'" + pierL[i] + "'";
                    else
                        s += ",'" + pierL[i] + "'";
                }
                rows = dtP.Select("Pier in (" + s + ")");
            }
            else
                rows = dtP.Select();
            if (rows.Length > 0)
            {
                string stNo = rows[0]["Pier"].ToString();
                string endNo = rows[rows.Length- 1]["Pier"].ToString();
                pierdiv = stNo + "-" + endNo;
                Table lasTb = new Table();
                ext = new Extents2d(M1.Convert2D(), M1.Convert2D());

                lasTb = DrawingBeamLineInfomationTable(db, ref ext, M1.Convert3D(),
                    Extensions.curFont, scale, dt, rows, dwgPath, title);
                double width = lasTb.Width;
                if (lasTb != null)
                {
                    string str1 = string.Format("INFORMATION SHEET OF CROSS BEAM FOR '{0}' TO '{1}' OF {2}", stNo, endNo, title);
                    string str2 = "";
                    TextPloter.PrintScaleDoubleSideText(db, M1.Convert2D(0, 0).Convert2D(width, 8 * scale), 3, str1, str2, ref ext, scale, Extensions.curFont);
                }
                Common.CreateLayoutNew(db, "平面信息表", ext, scale, 1, 0, 0, false, tkPath);
            }
        }
        /// <summary>
        /// 盖梁平面线路信息表格绘制
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="tbAValue"></param>
        /// <param name="tbBValue"></param>
        /// <param name="pierName"></param>
        /// <param name="_dwgPath"></param>
        /// <param name="Title"></param>
        /// <returns></returns>
        public static Table DrawingBeamLineInfomationTable(Database db, ref Extents2d ext, Point3d startPoint,
string txtStyle, double scale, System.Data.DataTable tbData, DataRow[] rows, string _dwgPath, string Title = "MAINLINE")
        {
          
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                int tCount = rows.Length;
                int tbNum = 1;
                int halfNum = 0;
                if (tCount>7)
                {
                    tbNum = 2;
                    halfNum = tCount / 2;
                    if (halfNum < tCount / 2.0)
                        halfNum += 1;
                }
              


                Table tb = new Table();
                #region  表格
                for (int n = 0; n < tbNum; n++)
                {
                    startPoint = startPoint.Convert3D(tb.Width);
                    tb = new Table();
                    int colNum = 11;
                    int rowNum = 2;
                    if (n == 0)
                        rowNum = halfNum * 4 + 2;
                    else
                        rowNum = (tCount-halfNum) * 4 + 2; 
                    tb.SetSize(rowNum, colNum);       // 设置几行几列
                    tb.Position = startPoint;
                    tb.GenerateLayout();

                    #region 设置列宽
                    // 设置列宽
                    for (int i = 0; i < colNum; ++i)
                    {
                        tb.Columns[i].Width = 6 * 3 * scale;
                    }


                    //行高
                    for (int i = 0; i < rowNum; ++i)
                    {
                        tb.Rows[i].Height = 4.5 * scale;
                    }
                    #endregion



                    tb.Cells[0, 0].TextString = "Location"; //获取i行j列数据
                    tb.Cells[0, 0].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 0].Contents[0].Rotation = 0;
                    tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 0].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 0, 1, 0));

                    tb.Cells[0, 1].TextString = "Pier No."; //获取i行j列数据
                    tb.Cells[0, 1].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 1].Contents[0].Rotation = 0;
                    tb.Cells[0, 1].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 1].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 1, 1, 1));

                    tb.Cells[0, 2].TextString = "Station"; //获取i行j列数据
                    tb.Cells[0, 2].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 2].Contents[0].Rotation = 0;
                    tb.Cells[0, 2].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 2].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 2, 1, 2));

                    tb.Cells[0, 3].TextString = "Type of\\P Cross beam"; //获取i行j列数据
                    tb.Cells[0, 3].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 3].Contents[0].Rotation = 0;
                    tb.Cells[0, 3].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 3, 1, 3));

                    tb.Cells[0, 4].TextString = "Type of\\P Column"; //获取i行j列数据
                    tb.Cells[0, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 4].Contents[0].Rotation = 0;
                    tb.Cells[0, 4].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 4].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 4, 1, 4));

                    tb.Cells[0, 5].TextString = "Height of\\P Cross beam\\P (m)"; //获取i行j列数据
                    tb.Cells[0, 5].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 5].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 5].Contents[0].Rotation = 0;
                    tb.Cells[0, 5].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 5].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 5, 1, 5));

                    tb.Cells[0, 6].TextString = "H1\\P (MSL/m)"; //获取i行j列数据
                    tb.Cells[0, 6].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 6].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 6].Contents[0].Rotation = 0;
                    tb.Cells[0, 6].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 6].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 6, 1, 6));

                    tb.Cells[0, 7].TextString = "H2\\P (MSL/m)"; //获取i行j列数据
                    tb.Cells[0, 7].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 7].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 7].Contents[0].Rotation = 0;
                    tb.Cells[0, 7].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 7].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 7, 1, 7));

                    tb.Cells[0, 8].TextString = "Point\\P No."; //获取i行j列数据
                    tb.Cells[0, 8].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 8].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 8].Contents[0].Rotation = 0;
                    tb.Cells[0, 8].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 8].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 8, 1, 8));
                    
                    tb.Cells[0, 9].TextString = "Coordinates (m)"; //获取i行j列数据
                    tb.Cells[0, 9].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 9].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 9].Contents[0].Rotation = 0;
                    tb.Cells[0, 9].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 9].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 9, 0, 10));                  

                    tb.Cells[1, 9].TextString = "N."; //获取i行j列数据
                    tb.Cells[1, 9].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 9].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 9].Contents[0].Rotation = 0;
                    tb.Cells[1, 9].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, 9].Contents[0].TextStyleId = id;

                    tb.Cells[1, 10].TextString = "E."; //获取i行j列数据
                    tb.Cells[1, 10].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 10].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 10].Contents[0].Rotation = 0;
                    tb.Cells[1, 10].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, 10].Contents[0].TextStyleId = id;

                    tb.Cells[2, 0].TextString = Title; //获取i行j列数据
                    tb.Cells[2, 0].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[2, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2, 0].Contents[0].Rotation = 0;
                    tb.Cells[2, 0].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[2, 0].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 2, 0, rowNum, 0));

                    for (int i = 0; i < halfNum; i++)
                    {
                        string pierNo = rows[i]["Pier"].ToString();
                        DataRow[] drs = tbData.Select("Pier='" + pierNo + "'");

                        tb.Cells[2 + i * 4, 1].TextString = pierNo;
                        tb.Cells[2 + i * 4, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 1].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 1].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 1].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 1, 2 + (i + 1) * 4, 1));

                        tb.Cells[2 + i * 4, 2].TextString = "";
                        tb.Cells[2 + i * 4, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 2].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 2].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 2].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 2, 2 + (i + 1) * 4, 2));


                        tb.Cells[2 + i * 4, 3].TextString = "";
                        tb.Cells[2 + i * 4, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 3].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 3].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 3].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 3, 2 + (i + 1) * 4, 3));

                        tb.Cells[2 + i * 4, 4].TextString = "";
                        tb.Cells[2 + i * 4, 4].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 4].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 4].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 4].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 4].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 4, 2 + (i + 1) * 4, 4));

                        tb.Cells[2 + i * 4, 5].TextString = "";
                        tb.Cells[2 + i * 4, 5].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 5].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 5].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 5].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 5].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 5, 2 + (i + 1) * 4, 5));

                        tb.Cells[2 + i * 4, 6].TextString = "";
                        tb.Cells[2 + i * 4, 6].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 6].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 6].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 6].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 6].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 6, 2 + (i + 1) * 4, 6));

                        tb.Cells[2 + i * 4, 7].TextString = "";
                        tb.Cells[2 + i * 4, 7].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 7].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 7].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 7].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 7].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 7, 2 + (i + 1) * 4, 7));

                        tb.Cells[2 + i * 4, 8].TextString = "";
                        tb.Cells[2 + i * 4, 8].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 8].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 8].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 8].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 8].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 8, 2 + (i + 1) * 4, 8));
                        for (int m = 0; m < 4; m++)
                        {
                            string val = "A";
                            switch (m)
                            {
                                case 0:
                                    val = "A";
                                    break;
                                case 1:
                                    val = "B";
                                    break;
                                case 2:
                                    val = "C";
                                    break;
                                case 3:
                                    val = "D";
                                    break;
                            }
                            tb.Cells[2 + i * 4 + m, 9].TextString = val;
                            tb.Cells[2 + i * 4 + m, 9].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[2 + i * 4 + m, 9].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[2 + i * 4 + m, 9].Contents[0].Rotation = 0;
                            tb.Cells[2 + i * 4 + m, 9].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[2 + i * 4 + m, 9].Contents[0].TextStyleId = id;

                            tb.Cells[2 + i * 4 + m, 10].TextString = "";
                            tb.Cells[2 + i * 4 + m, 10].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[2 + i * 4 + m, 10].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[2 + i * 4 + m, 10].Contents[0].Rotation = 0;
                            tb.Cells[2 + i * 4 + m, 10].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[2 + i * 4 + m, 10].Contents[0].TextStyleId = id;

                            tb.Cells[2 + i * 4 + m, 11].TextString = "";
                            tb.Cells[2 + i * 4 + m, 11].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[2 + i * 4 + m, 11].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[2 + i * 4 + m, 11].Contents[0].Rotation = 0;
                            tb.Cells[2 + i * 4 + m, 11].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[2 + i * 4 + m, 11].Contents[0].TextStyleId = id;

                        }
                    }

                    tb.Layer = "细线";
                    tb.LineWeight = LineWeight.LineWeight013;
                    tb.ColorIndex = 4;
                    modelSpace.AppendEntity(tb);
                    tr.AddNewlyCreatedDBObject(tb, true);
                    ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));
                }
                #endregion

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D(-tb.Width);
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width * 2, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width * 2, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion               

                tr.Commit();
                return tb;
            }
        }
        #endregion

        #region 墩柱平面线路信息表
        /// <summary>
        /// 盖梁平面线路信息表格绘制
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="tbAValue"></param>
        /// <param name="tbBValue"></param>
        /// <param name="pierName"></param>
        /// <param name="_dwgPath"></param>
        /// <param name="Title"></param>
        /// <returns></returns>
        public static Table DrawingColumnLineInfomationTable(Database db, ref Extents2d ext, Point3d startPoint,
string txtStyle, double scale, System.Data.DataTable tbData, DataRow[] rows, string _dwgPath, string Title = "MAINLINE")
        {

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                int tCount = rows.Length;
                int tbNum = 1;
                int halfNum = 0;
                if (tCount > 7)
                {
                    tbNum = 2;
                    halfNum = tCount / 2;
                    if (halfNum < tCount / 2.0)
                        halfNum += 1;
                }



                Table tb = new Table();
                #region  表格
                for (int n = 0; n < tbNum; n++)
                {
                    startPoint = startPoint.Convert3D(tb.Width);
                    tb = new Table();
                    int colNum = 12;
                    int rowNum = 2;
                    if (n == 0)
                        rowNum = halfNum * 4 + 2;
                    else
                        rowNum = (tCount - halfNum) * 4 + 2;
                    tb.SetSize(rowNum, colNum);       // 设置几行几列
                    tb.Position = startPoint;
                    tb.GenerateLayout();

                    #region 设置列宽
                    // 设置列宽
                    for (int i = 0; i < colNum; ++i)
                    {
                        tb.Columns[i].Width = 6 * 3 * scale;
                    }


                    //行高
                    for (int i = 0; i < rowNum; ++i)
                    {
                        tb.Rows[i].Height = 4.5 * scale;
                    }
                    #endregion



                    tb.Cells[0, 0].TextString = "Location"; //获取i行j列数据
                    tb.Cells[0, 0].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 0].Contents[0].Rotation = 0;
                    tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 0].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 0, 1, 0));

                    tb.Cells[0, 1].TextString = "Pier No."; //获取i行j列数据
                    tb.Cells[0, 1].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 1].Contents[0].Rotation = 0;
                    tb.Cells[0, 1].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 1].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 1, 1, 1));

                    tb.Cells[0, 2].TextString = "Station"; //获取i行j列数据
                    tb.Cells[0, 2].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 2].Contents[0].Rotation = 0;
                    tb.Cells[0, 2].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 2].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 2, 1, 2));

                    tb.Cells[0, 3].TextString = "Column\\P No."; //获取i行j列数据
                    tb.Cells[0, 3].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 3].Contents[0].Rotation = 0;
                    tb.Cells[0, 3].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 3, 1, 3));

                    tb.Cells[0, 4].TextString = "Type of\\P Footing"; //获取i行j列数据
                    tb.Cells[0, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 4].Contents[0].Rotation = 0;
                    tb.Cells[0, 4].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 4].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 4, 1, 4));

                    tb.Cells[0, 5].TextString = "Type of\\P Column"; //获取i行j列数据
                    tb.Cells[0, 5].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 5].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 5].Contents[0].Rotation = 0;
                    tb.Cells[0, 5].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 5].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 5, 1, 5));

                    tb.Cells[0, 6].TextString = "Column\\P Height\\P (m)"; //获取i行j列数据
                    tb.Cells[0, 6].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 6].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 6].Contents[0].Rotation = 0;
                    tb.Cells[0, 6].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 6].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 6, 1, 6));

                    tb.Cells[0, 7].TextString = "Elevation at top\\P of column\\P (MSL/m)"; //获取i行j列数据
                    tb.Cells[0, 7].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 7].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 7].Contents[0].Rotation = 0;
                    tb.Cells[0, 7].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 7].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 7, 1, 7));

                    tb.Cells[0, 8].TextString = "Elevation at bottom\\P of column\\P (MSL/m)"; //获取i行j列数据
                    tb.Cells[0, 8].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 8].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 8].Contents[0].Rotation = 0;
                    tb.Cells[0, 8].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 8].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 8, 1, 8));

                    tb.Cells[0, 9].TextString = "Point\\P No."; //获取i行j列数据
                    tb.Cells[0, 9].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 9].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 9].Contents[0].Rotation = 0;
                    tb.Cells[0, 9].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 9].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 9, 1, 9));

                    tb.Cells[0, 10].TextString = "Coordinates (m)"; //获取i行j列数据
                    tb.Cells[0, 10].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 10].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 10].Contents[0].Rotation = 0;
                    tb.Cells[0, 10].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 10].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 10, 0, 11));

                    tb.Cells[1, 11].TextString = "N."; //获取i行j列数据
                    tb.Cells[1, 11].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 11].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 11].Contents[0].Rotation = 0;
                    tb.Cells[1, 11].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, 11].Contents[0].TextStyleId = id;

                    tb.Cells[1, 12].TextString = "E."; //获取i行j列数据
                    tb.Cells[1, 12].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 12].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 12].Contents[0].Rotation = 0;
                    tb.Cells[1, 12].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, 12].Contents[0].TextStyleId = id;

                    tb.Cells[2, 0].TextString = Title; //获取i行j列数据
                    tb.Cells[2, 0].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[2, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2, 0].Contents[0].Rotation = 0;
                    tb.Cells[2, 0].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[2, 0].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 2, 0, rowNum, 0));

                    for (int i = 0; i < halfNum; i++)
                    {
                        string pierNo = rows[i]["Pier"].ToString();
                        DataRow[] drs = tbData.Select("Pier='" + pierNo + "'");

                        tb.Cells[2 + i * 4, 1].TextString = pierNo;
                        tb.Cells[2 + i * 4, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 1].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 1].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 1].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 1, 2 + (i + 1) * 4, 1));

                        tb.Cells[2 + i * 4, 2].TextString = "";
                        tb.Cells[2 + i * 4, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 2].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 2].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 2].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 2, 2 + (i + 1) * 4, 2));


                        tb.Cells[2 + i * 4, 3].TextString = "";
                        tb.Cells[2 + i * 4, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 3].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 3].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 3].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 3, 2 + (i + 1) * 4, 3));

                        tb.Cells[2 + i * 4, 4].TextString = "";
                        tb.Cells[2 + i * 4, 4].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 4].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 4].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 4].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 4].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 4, 2 + (i + 1) * 4, 4));

                        tb.Cells[2 + i * 4, 5].TextString = "";
                        tb.Cells[2 + i * 4, 5].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 5].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 5].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 5].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 5].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 5, 2 + (i + 1) * 4, 5));

                        tb.Cells[2 + i * 4, 6].TextString = "";
                        tb.Cells[2 + i * 4, 6].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 6].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 6].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 6].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 6].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 6, 2 + (i + 1) * 4, 6));

                        tb.Cells[2 + i * 4, 7].TextString = "";
                        tb.Cells[2 + i * 4, 7].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 7].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 7].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 7].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 7].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 7, 2 + (i + 1) * 4, 7));

                        for (int m = 0; m < 4; m++)
                        {
                            string val = "A";
                            switch (m)
                            {
                                case 0:
                                    val = "A";
                                    break;
                                case 1:
                                    val = "B";
                                    break;
                                case 2:
                                    val = "C";
                                    break;
                                case 3:
                                    val = "D";
                                    break;
                            }
                            tb.Cells[2 + i * 4 + m, 8].TextString = val;
                            tb.Cells[2 + i * 4 + m, 8].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[2 + i * 4 + m, 8].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[2 + i * 4 + m, 8].Contents[0].Rotation = 0;
                            tb.Cells[2 + i * 4 + m, 8].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[2 + i * 4 + m, 8].Contents[0].TextStyleId = id;

                            tb.Cells[2 + i * 4 + m, 9].TextString = "";
                            tb.Cells[2 + i * 4 + m, 9].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[2 + i * 4 + m, 9].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[2 + i * 4 + m, 9].Contents[0].Rotation = 0;
                            tb.Cells[2 + i * 4 + m, 9].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[2 + i * 4 + m, 9].Contents[0].TextStyleId = id;

                            tb.Cells[2 + i * 4 + m, 10].TextString = "";
                            tb.Cells[2 + i * 4 + m, 10].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[2 + i * 4 + m, 10].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[2 + i * 4 + m, 10].Contents[0].Rotation = 0;
                            tb.Cells[2 + i * 4 + m, 10].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[2 + i * 4 + m, 10].Contents[0].TextStyleId = id;
                        }
                    }

                    tb.Layer = "细线";
                    tb.LineWeight = LineWeight.LineWeight013;
                    tb.ColorIndex = 4;
                    modelSpace.AppendEntity(tb);
                    tr.AddNewlyCreatedDBObject(tb, true);
                    ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));
                }
                #endregion

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D(-tb.Width);
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width * 2, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width * 2, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion               

                tr.Commit();
                return tb;
            }
        }
        #endregion

        #region 承台平面线路信息表
        /// <summary>
        /// 盖梁平面线路信息表格绘制
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="tbAValue"></param>
        /// <param name="tbBValue"></param>
        /// <param name="pierName"></param>
        /// <param name="_dwgPath"></param>
        /// <param name="Title"></param>
        /// <returns></returns>
        public static Table DrawingFootingLineInfomationTable(Database db, ref Extents2d ext, Point3d startPoint,
string txtStyle, double scale, System.Data.DataTable tbData, DataRow[] rows, string _dwgPath, string Title = "MAINLINE")
        {

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                int tCount = rows.Length;
                int tbNum = 1;
                int halfNum = 0;
                if (tCount > 7)
                {
                    tbNum = 2;
                    halfNum = tCount / 2;
                    if (halfNum < tCount / 2.0)
                        halfNum += 1;
                }



                Table tb = new Table();
                #region  表格
                for (int n = 0; n < tbNum; n++)
                {
                    startPoint = startPoint.Convert3D(tb.Width);
                    tb = new Table();
                    int colNum = 12;
                    int rowNum = 2;
                    if (n == 0)
                        rowNum = halfNum * 4 + 2;
                    else
                        rowNum = (tCount - halfNum) * 4 + 2;
                    tb.SetSize(rowNum, colNum);       // 设置几行几列
                    tb.Position = startPoint;
                    tb.GenerateLayout();

                    #region 设置列宽
                    // 设置列宽
                    for (int i = 0; i < colNum; ++i)
                    {
                        tb.Columns[i].Width = 6 * 3 * scale;
                    }


                    //行高
                    for (int i = 0; i < rowNum; ++i)
                    {
                        tb.Rows[i].Height = 4.5 * scale;
                    }
                    #endregion



                    tb.Cells[0, 0].TextString = "Location"; //获取i行j列数据
                    tb.Cells[0, 0].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 0].Contents[0].Rotation = 0;
                    tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 0].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 0, 1, 0));

                    tb.Cells[0, 1].TextString = "Pier No."; //获取i行j列数据
                    tb.Cells[0, 1].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 1].Contents[0].Rotation = 0;
                    tb.Cells[0, 1].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 1].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 1, 1, 1));

                    tb.Cells[0, 2].TextString = "Station"; //获取i行j列数据
                    tb.Cells[0, 2].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 2].Contents[0].Rotation = 0;
                    tb.Cells[0, 2].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 2].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 2, 1, 2));

                    tb.Cells[0, 3].TextString = "Footing\\P No."; //获取i行j列数据
                    tb.Cells[0, 3].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 3].Contents[0].Rotation = 0;
                    tb.Cells[0, 3].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 3].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 3, 1, 3));

                    tb.Cells[0, 4].TextString = "Type of\\P Footing"; //获取i行j列数据
                    tb.Cells[0, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 4].Contents[0].Rotation = 0;
                    tb.Cells[0, 4].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 4].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 4, 1, 4));

                    tb.Cells[0, 5].TextString = "Type of\\P Column"; //获取i行j列数据
                    tb.Cells[0, 5].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 5].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 5].Contents[0].Rotation = 0;
                    tb.Cells[0, 5].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 5].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 5, 1, 5));

                    tb.Cells[0, 6].TextString = "Column\\P Height\\P (m)"; //获取i行j列数据
                    tb.Cells[0, 6].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 6].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 6].Contents[0].Rotation = 0;
                    tb.Cells[0, 6].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 6].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 6, 1, 6));

                    tb.Cells[0, 7].TextString = "Elevation at top\\P of footing\\P (MSL/m)"; //获取i行j列数据
                    tb.Cells[0, 7].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 7].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 7].Contents[0].Rotation = 0;
                    tb.Cells[0, 7].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 7].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 7, 1, 7));

                    tb.Cells[0, 8].TextString = "Elevation at bottom\\P of footing\\P (MSL/m)"; //获取i行j列数据
                    tb.Cells[0, 8].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 8].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 8].Contents[0].Rotation = 0;
                    tb.Cells[0, 8].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 8].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 8, 1, 8));

                    tb.Cells[0, 9].TextString = "Point\\P No."; //获取i行j列数据
                    tb.Cells[0, 9].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 9].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 9].Contents[0].Rotation = 0;
                    tb.Cells[0, 9].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 9].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 9, 1, 9));

                    tb.Cells[0, 10].TextString = "Coordinates (m)"; //获取i行j列数据
                    tb.Cells[0, 10].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[0, 10].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, 10].Contents[0].Rotation = 0;
                    tb.Cells[0, 10].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, 10].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 0, 10, 0, 11));

                    tb.Cells[1, 11].TextString = "N."; //获取i行j列数据
                    tb.Cells[1, 11].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 11].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 11].Contents[0].Rotation = 0;
                    tb.Cells[1, 11].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, 11].Contents[0].TextStyleId = id;

                    tb.Cells[1, 12].TextString = "E."; //获取i行j列数据
                    tb.Cells[1, 12].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 12].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 12].Contents[0].Rotation = 0;
                    tb.Cells[1, 12].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, 12].Contents[0].TextStyleId = id;

                    tb.Cells[2, 0].TextString = Title; //获取i行j列数据
                    tb.Cells[2, 0].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[2, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2, 0].Contents[0].Rotation = 0;
                    tb.Cells[2, 0].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[2, 0].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, 2, 0, rowNum, 0));

                    for (int i = 0; i < halfNum; i++)
                    {
                        string pierNo = rows[i]["Pier"].ToString();
                        DataRow[] drs = tbData.Select("Pier='" + pierNo + "'");

                        tb.Cells[2 + i * 4, 1].TextString = pierNo;
                        tb.Cells[2 + i * 4, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 1].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 1].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 1].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 1, 2 + (i + 1) * 4, 1));

                        tb.Cells[2 + i * 4, 2].TextString = "";
                        tb.Cells[2 + i * 4, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 2].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 2].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 2].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 2, 2 + (i + 1) * 4, 2));


                        tb.Cells[2 + i * 4, 3].TextString = "";
                        tb.Cells[2 + i * 4, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 3].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 3].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 3].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 3, 2 + (i + 1) * 4, 3));

                        tb.Cells[2 + i * 4, 4].TextString = "";
                        tb.Cells[2 + i * 4, 4].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 4].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 4].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 4].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 4].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 4, 2 + (i + 1) * 4, 4));

                        tb.Cells[2 + i * 4, 5].TextString = "";
                        tb.Cells[2 + i * 4, 5].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 5].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 5].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 5].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 5].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 5, 2 + (i + 1) * 4, 5));

                        tb.Cells[2 + i * 4, 6].TextString = "";
                        tb.Cells[2 + i * 4, 6].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 6].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 6].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 6].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 6].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 6, 2 + (i + 1) * 4, 6));

                        tb.Cells[2 + i * 4, 7].TextString = "";
                        tb.Cells[2 + i * 4, 7].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 7].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 7].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 7].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 7].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 7, 2 + (i + 1) * 4, 7));

                        tb.Cells[2 + i * 4, 8].TextString = "";
                        tb.Cells[2 + i * 4, 8].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[2 + i * 4, 8].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2 + i * 4, 8].Contents[0].Rotation = 0;
                        tb.Cells[2 + i * 4, 8].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[2 + i * 4, 8].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 2, 8, 2 + (i + 1) * 4, 8));
                        for (int m = 0; m < 4; m++)
                        {
                            string val = "A";
                            switch (m)
                            {
                                case 0:
                                    val = "A";
                                    break;
                                case 1:
                                    val = "B";
                                    break;
                                case 2:
                                    val = "C";
                                    break;
                                case 3:
                                    val = "D";
                                    break;
                            }
                            tb.Cells[2 + i * 4 + m, 9].TextString = val;
                            tb.Cells[2 + i * 4 + m, 9].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[2 + i * 4 + m, 9].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[2 + i * 4 + m, 9].Contents[0].Rotation = 0;
                            tb.Cells[2 + i * 4 + m, 9].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[2 + i * 4 + m, 9].Contents[0].TextStyleId = id;

                            tb.Cells[2 + i * 4 + m, 10].TextString = "";
                            tb.Cells[2 + i * 4 + m, 10].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[2 + i * 4 + m, 10].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[2 + i * 4 + m, 10].Contents[0].Rotation = 0;
                            tb.Cells[2 + i * 4 + m, 10].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[2 + i * 4 + m, 10].Contents[0].TextStyleId = id;

                            tb.Cells[2 + i * 4 + m, 11].TextString = "";
                            tb.Cells[2 + i * 4 + m, 11].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[2 + i * 4 + m, 11].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[2 + i * 4 + m, 11].Contents[0].Rotation = 0;
                            tb.Cells[2 + i * 4 + m, 11].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[2 + i * 4 + m, 11].Contents[0].TextStyleId = id;

                        }
                    }

                    tb.Layer = "细线";
                    tb.LineWeight = LineWeight.LineWeight013;
                    tb.ColorIndex = 4;
                    modelSpace.AppendEntity(tb);
                    tr.AddNewlyCreatedDBObject(tb, true);
                    ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));
                }
                #endregion

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D(-tb.Width);
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width * 2, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width * 2, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion               

                tr.Commit();
                return tb;
            }
        }
        #endregion
    }
}
